<template>
	<view>
		<view class="cu-custom" :style="{'height':(CustomBar+addHeight)+'px'}">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'']">
				<block v-if="isBack">
					<view class="action" @tap="BackPage">
						<text class="cuIcon-back"></text>
						<slot name="backText"></slot>
					</view>
				</block>
				<block v-else-if="isPortrait">
					<view class="action" @tap="BackPage">
						<view class="portrait">
							<open-data type="userAvatarUrl" style="width: 100%;height: 100%;display: inline-block;"></open-data>
						</view>
					</view>
				</block>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
			<view class="add-height" :style="{'height':addHeight+'px'}"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var bgImage = this.bgImage;
				var bgColor = this.bgColor
				var addHeight = this.addHeight
				var style = `height:${CustomBar+addHeight}px;padding-top:${StatusBar}px;background-color:${bgColor};`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: '#1F988C'
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
			isPortrait: {
				type: [Boolean, String],
				default: false
			},
			addHeight: {
				type: Number,
				default: 0
			}
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	.cu-custom {
		.action {
			color: #FFFFFF;

			.portrait {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
				overflow: hidden;
				display: block;
				vertical-align: middle;
			}
		}

		.content {
			color: #FFFFFF;
			font-size: 32upx;

		}
	}

	.add-height {
		background-color: $index-color;
	}
</style>
